Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: genf macro lineno #84

Merged
merged 1 commit into from
Feb 28, 2024
Merged

FIX: genf macro lineno #84

merged 1 commit into from
Feb 28, 2024

Conversation

ismagilli
Copy link
Contributor

@ismagilli ismagilli commented Feb 23, 2024

The correct line number of the source file for the generated code.

See for example following code and it's output:

#include <stdio.h>

#define genf(out, ...)                                     \
    do {                                                   \
        fprintf((out), __VA_ARGS__);                       \
        fprintf((out), " // %s:%d\n", __FILE__, __LINE__); \
    } while (0)

int main(void) {
    genf(stdout, "Hello, world");
}

@ismagilli
Copy link
Contributor Author

ismagilli commented Feb 23, 2024

For code

void f(void) {  // line 1
    int x = 10  // line 2
    int y = 20; // line 3
}               // line 4

the compiler says that an error on line 3 because after 10 it try to read something different from int (operator / , / ;), but it read int.
Compiler output:

<source>: In function 'f':
<source>:3:5: error: expected ',' or ';' before 'int'
    3 |     int y = 20;
      |     ^~~
Compiler returned: 1

In this case, the real error in line 2. On stream you have situation like following:

genf("int x = 10");  // line N
genf("int y = 20;"); // line N+1

The compiler says that the error in the code is generated by line N+1, but you know that error in the сode is generated by line N. This led to the erroneous assumption that it is necessary to subtract one.

@rexim
Copy link
Member

rexim commented Feb 28, 2024

Yeah, I think there was something wrong with my Emacs at the time of writing this. Its go to line command had off by one moment for whatever reason. Now it's fine. Thanks!

@rexim rexim merged commit 07935b1 into tsoding:master Feb 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants